DV = input() 
p = [] 
if len(DV) == 4: 
    def Sorting(bebr): 
        if bebr == 1:
            return True 
        for i in range(2, bebr):
            if bebr % i == 0:
                return False 
        return True
    for i in range(1, 5): 
        for i2 in range(0, 4):
            if i + i2 <= 4 and Sorting(int(DV[i2:i+i2])) == True: 
                p.append(int(DV[i2:i+i2]))
    if p:
        p.sort(reverse = True)
        print(p[0]) 
    else:
        print(0)
else:
    print(0)